package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.GoodsEvaluateCommentAddRequest;
import com.frogs.ucenter.v1.request.GoodsEvaluateCommentDeleteRequest;
import com.frogs.ucenter.v1.request.GoodsEvaluateCommentListRequest;
import com.frogs.ucenter.v1.service.GoodsEvaluateCommentService;
import com.frogs.ucenter.v1.util.ApiConstants;

/**
 *
 * @author lijian
 * @version 2014年3月17日 - 上午10:53:33
 */
@Controller(ApiConstants.VERSION+"goodsEvaluateCommentController")
@RequestMapping("/"+ApiConstants.VERSION)
public class GoodsEvaluateCommentController extends BaseController3 {

	private static final String ROOT = "/goods";
	private static final String GOODS_EVALUATE_COMMENT_ADD = ROOT + "/evaluate/comment/add";
	private static final String GOODS_EVALUATE_COMMENT_DELETE = ROOT + "/evaluate/comment/delete";
	private static final String GOODS_EVALUATE_COMMENT_LIST = ROOT + "/evaluate/comment/list";
	
	@Resource(name=ApiConstants.VERSION + "goodsEvaluateCommentService")
	private GoodsEvaluateCommentService goodsEvaluateCommentService;
	
	/**
	 * 商品评价评论接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/user/goodsEvaluateComment/add.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	@RequestMapping({GOODS_EVALUATE_COMMENT_ADD})
	public Response goodsEvaluateCommentAdd(HttpServletRequest request) {
		Response response = null;
		try {
			GoodsEvaluateCommentAddRequest evaluateCommentAddRequest = new GoodsEvaluateCommentAddRequest();
			evaluateCommentAddRequest.parse(request);
			response = goodsEvaluateCommentService.addGoodsEvaluateCommentInfo(evaluateCommentAddRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 删除商品评价评论接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/user/goodsEvaluateComment/delete.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	
	@RequestMapping({GOODS_EVALUATE_COMMENT_DELETE})
	public Response goodsEvaluateCommentDelete(HttpServletRequest request) {
		Response response = null;
		try {
			GoodsEvaluateCommentDeleteRequest evaluateCommentDeleteRequest = new GoodsEvaluateCommentDeleteRequest();
			evaluateCommentDeleteRequest.parse(request);
			response = goodsEvaluateCommentService.deleteGoodsEvaluateCommentInfo(evaluateCommentDeleteRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 获取商品评价评论接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/user/goodsEvaluateComment/list.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	
	@RequestMapping({GOODS_EVALUATE_COMMENT_LIST})
	public Response goodsEvaluateCommentList(HttpServletRequest request) {
		Response response = null;
		try {
			GoodsEvaluateCommentListRequest evaluateCommentListRequest = new GoodsEvaluateCommentListRequest();
			evaluateCommentListRequest.parse(request);
			response = goodsEvaluateCommentService.getGoodsEvaluateCommentList(evaluateCommentListRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
}
